package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test5 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method[] method = cls.getDeclaredMethods();
        for (Method methods : method) {
//            判断该方法是否无参数
            if (methods.getParameterCount() == 0
                    &&
//                    判断该方法是否为公开方法
                    methods.getModifiers() == Modifier.PUBLIC) {
                System.out.println(methods.getName());
                methods.invoke(obj);
            }
        }
    }
}
